// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1

Item{
    id: _root
    width: _a1.width + _a2.width
    height: _a1.height

    property variant numberPics: []
    property variant weekdayPics: []
    property string yearStrPic: "images/lock_year.png"
    property string monthStrPic: "images/lock_week_mon.png"
    property string dayStrPic: "images/lock_week_sun.png"
    property string lcStrPic: "images/lock_calendar_lC.png"
    property string rcStrPic: "images/lock_calendar_RC.png"

    property bool isViewYear: false
    property bool isWrap: false
    property bool isViewC: true

    Component.onCompleted: {
        updateCalendar();
    }

    Timer{
        interval: 10000
        repeat: true
        running: true
        onTriggered: {
            updateCalendar();
        }
    }
    function updateCalendar(){
        var d = new Date();
        var y1 = Math.floor(d.getFullYear() / 1000);
        var y2 = Math.floor(d.getFullYear() / 100 % 10);
        var y3 = Math.floor(d.getFullYear() / 10 % 10);
        var y4 = Math.floor(d.getFullYear() % 10);
        var m1 = Math.floor((d.getMonth()+1) / 10);
        var m2 = (d.getMonth()+1) % 10;
        var d1 = Math.floor(d.getDate() / 10);
        var d2 = d.getDate() % 10;
        var w = d.getDay();

        _y1.source = numberPics[y1];
        _y2.source = numberPics[y2];
        _y3.source = numberPics[y3];
        _y4.source = numberPics[y4];
        if(d.getMonth() >= 9){
            _m1.visible = true;
            _m1.source = numberPics[m1];
        }else{
            _m1.visible = false;
        }
        _m2.source = numberPics[m2];
        _d1.source = numberPics[d1];
        _d2.source = numberPics[d2];
        _w.source = weekdayPics[w];
    }

    //月と日と（）
//    Image{
//        id: _base
//        x: 17 * viewScale
//        y: 0 * viewScale
//        width: basePicWidth
//        height: basePicHeight
//        smooth: true
//        source: basePic
//    }
    Row{
        id: _a1
        spacing: 2
        //年
        Image{
            id: _y1
            y: 2 * viewScale
            fillMode: Image.PreserveAspectFit
            height: 20 * viewScale
            smooth: true
            source: ""
            visible: isViewYear
        }
        Image{
            id: _y2
            y: 2 * viewScale
            fillMode: Image.PreserveAspectFit
            height: 20 * viewScale
            smooth: true
            source: ""
            visible: isViewYear
        }
        Image{
            id: _y3
            y: 2 * viewScale
            fillMode: Image.PreserveAspectFit
            height: 20 * viewScale
            smooth: true
            source: ""
            visible: isViewYear
        }
        Image{
            id: _y4
            y: 2 * viewScale
            fillMode: Image.PreserveAspectFit
            height: 20 * viewScale
            smooth: true
            source: ""
            visible: isViewYear
        }
        Image{
            id: _ys
            y: 0 * viewScale
            fillMode: Image.PreserveAspectFit
            height: 24 * viewScale
            smooth: true
            source: yearStrPic
            visible: isViewYear
        }

        //月
        Image{
            id: _m1
            y: 2 * viewScale
            fillMode: Image.PreserveAspectFit
            height: 20 * viewScale
            smooth: true
            source: ""
        }
        Image{
            id: _m2
            y: 2 * viewScale
            fillMode: Image.PreserveAspectFit
            height: 20 * viewScale
            smooth: true
            source: ""
        }
        Image{
            id: _ms
            y: 0 * viewScale
            fillMode: Image.PreserveAspectFit
            height: 24 * viewScale
            smooth: true
            source: monthStrPic
        }
        //日
        Image{
            id: _d1
            y: 2 * viewScale
            fillMode: Image.PreserveAspectFit
            height: 20 * viewScale
            smooth: true
            source: ""
        }
        Image{
            id: _d2
            y: 2 * viewScale
            fillMode: Image.PreserveAspectFit
            height: 20 * viewScale
            smooth: true
            source: ""
        }
        Image{
            id: _ds
            y: 0 * viewScale
            fillMode: Image.PreserveAspectFit
            height: 24 * viewScale
            smooth: true
            source: dayStrPic
        }
    }
    //曜日
    Row{
        id: _a2
        anchors.left: _a1.right
        anchors.top: _a1.top
        anchors.margins: isWrap ? 2 : 0
        Image{
            id: _lc
            y: 0 * viewScale
            fillMode: Image.PreserveAspectFit
            height: 24 * viewScale
            smooth: true
            source: lcStrPic
            visible: isViewC
        }
        Image{
            id: _w
            y: 0 * viewScale
            fillMode: Image.PreserveAspectFit
            height: 24 * viewScale
            smooth: true
            source: ""
        }
        Image{
            id: _rc
            y: 0 * viewScale
            fillMode: Image.PreserveAspectFit
            height: 24 * viewScale
            smooth: true
            source: rcStrPic
            visible: isViewC
        }
    }

    states: [
        State{
            when: isWrap
            PropertyChanges {
                target: _root
                width: _a1.width
                height: _a1.height + _a2.height + _a2.anchors.margins
            }
            AnchorChanges {
                target: _a2
                anchors.left: _a1.left
                anchors.top: _a1.bottom
            }
        }

    ]
}
